Skip to content

fix(api): fall back to WEB_URL when Redis origin key is missing (#9354)#9361

Open
reachsanjivbhagat-gif wants to merge 1 commit into
makeplane:previewfrom
reachsanjivbhagat-gif:fix/9354-email-notification-fallback
Open

fix(api): fall back to WEB_URL when Redis origin key is missing (#9354)#9361
reachsanjivbhagat-gif wants to merge 1 commit into
makeplane:previewfrom
reachsanjivbhagat-gif:fix/9354-email-notification-fallback

Conversation

@reachsanjivbhagat-gif

@reachsanjivbhagat-gif reachsanjivbhagat-gif commented Jul 6, 2026

Copy link
Copy Markdown

Description

send_email_notification in apps/api/plane/bgtasks/email_notification_task.py silently dropped email notifications, while still reporting the Celery task as successful, whenever the Redis-cached "origin" key for an issue was missing. This happens whenever Redis restarts/evicts the key, more than 10 minutes (the key's TTL) pass before the email task runs, or the triggering activity was queued without an origin at all.

This PR replaces the silent early return with a fallback to settings.WEB_URL for constructing links in the email, and adds a logging.warning call so the condition is observable in logs instead of failing silently.

Type of Change

Bug fix (non-breaking change which fixes an issue).

Screenshots and Media (if applicable)

Not applicable, this is a backend logic change with no UI impact.

Test Scenarios

Manually traced the code path: with the Redis key absent, base_api now falls back to settings.WEB_URL and a warning is logged instead of the function returning early. Confirmed the rest of send_email_notification (payload creation, email rendering, and sending) proceeds unchanged after the fallback.

References

Fixes #9354

Summary by CodeRabbit

  • Bug Fixes
    • Email notifications now still generate links when the cached API origin is unavailable.
    • Added a fallback to the main web address and a warning log instead of stopping the notification flow.

…plane#9354)

send_email_notification silently dropped email notifications (while still reporting task success) whenever the Redis-cached origin key for an issue was missing due to TTL expiry, a Redis restart, or the activity being queued without an origin.

This change replaces the silent early return with a fallback to settings.WEB_URL for link construction, plus a warning log so the condition is observable.

Fixes makeplane#9354
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The send_email_notification task now imports Django settings and, when the Redis-cached base_api for an issue is missing, logs a warning and falls back to settings.WEB_URL instead of returning early and silently dropping the email.

Changes

Email Notification Fallback

Layer / File(s) Summary
base_api fallback on missing Redis cache
apps/api/plane/bgtasks/email_notification_task.py
Imports settings and replaces the early return when the Redis origin key is missing with a warning log plus a fallback to settings.WEB_URL for constructing email links.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Related issues: Fixes #9354 — silently dropped emails when Redis origin key is missing are now sent using a settings.WEB_URL fallback with a warning log instead of a silent early return.

Suggested labels: bug, backend

Suggested reviewers: none

Poem

A rabbit hopped through Redis' door,
Found the key missing, gone once more,
No longer silent, no more retreat—
It logs a warning, keeps the beat,
And sends the mail through WEB_URL's floor. 🐇✉️

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main fix: falling back to WEB_URL when the Redis origin key is missing.
Description check ✅ Passed The PR description follows the template and includes the change, type, media note, tests, and reference.
Linked Issues check ✅ Passed The change implements the requested WEB_URL fallback and warning for the missing Redis origin key in #9354.
Out of Scope Changes check ✅ Passed The patch stays focused on the email notification fallback and logging change, with no unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
apps/api/plane/bgtasks/email_notification_task.py (1)

167-172: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Fallback correctly avoids silent drop, but settings.WEB_URL isn't validated.

This correctly addresses the PR objective of not silently dropping notifications. However, settings.WEB_URL is derived from os.environ.get("WEB_URL") with no default, so if it's unset/empty in a given deployment, the fallback substitutes one falsy value for another and the generated links (avatar/issue/project URLs) will be malformed (e.g., "None/<workspace>/projects/...") while the email still sends successfully.

Consider tightening the warning to also flag when the fallback itself is unusable:

💡 Suggested tweak
             if not base_api:
-                logging.getLogger("plane.worker").warning(
-                    f"Redis origin key missing for issue {issue_id}; falling back to WEB_URL for email notification links"
-                )
                 base_api = settings.WEB_URL
+                if not base_api:
+                    logging.getLogger("plane.worker").error(
+                        f"Redis origin key missing for issue {issue_id} and settings.WEB_URL is also unset; "
+                        "email notification links may be malformed"
+                    )
+                else:
+                    logging.getLogger("plane.worker").warning(
+                        f"Redis origin key missing for issue {issue_id}; falling back to WEB_URL for email notification links"
+                    )
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/api/plane/bgtasks/email_notification_task.py` around lines 167 - 172,
The fallback in email_notification_task’s base URL handling is still unsafe
because settings.WEB_URL can be unset or empty, leading to malformed links while
notifications still send. Update the logic in the email notification flow around
the base_api fallback so it validates settings.WEB_URL before assigning it, and
if both the cached origin and WEB_URL are unusable, log a clear warning through
plane.worker and avoid building broken avatar/issue/project URLs.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@apps/api/plane/bgtasks/email_notification_task.py`:
- Around line 167-172: The fallback in email_notification_task’s base URL
handling is still unsafe because settings.WEB_URL can be unset or empty, leading
to malformed links while notifications still send. Update the logic in the email
notification flow around the base_api fallback so it validates settings.WEB_URL
before assigning it, and if both the cached origin and WEB_URL are unusable, log
a clear warning through plane.worker and avoid building broken
avatar/issue/project URLs.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7caadd8a-122d-4162-9a76-b62473fe9532

📥 Commits

Reviewing files that changed from the base of the PR and between 7fbf14a and 6d21db0.

📒 Files selected for processing (1)
  • apps/api/plane/bgtasks/email_notification_task.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 Bug: send_email_notification silently drops emails (task reports success) when the Redis origin key is missing

2 participants